home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / pump_src / setup / ems.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-09-30  |  4.1 KB  |  129 lines

  1. Unit EMS;
  2.  
  3. Interface
  4.  
  5. Function EMM_Installed:Boolean;
  6.  
  7. Implementation
  8.  
  9. uses Dos,Crt;
  10. Type
  11.   ST3  = string[3];
  12.   ST80 = string[80];
  13.   ST5  = string[5];
  14.  
  15. Const
  16.   EMM_INT                    = $67;
  17.   DOS_Int                    = $21;
  18.   GET_PAGE_FRAME             = $41;
  19.   GET_UNALLOCATED_PAGE_COUNT = $42;
  20.   ALLOCATE_PAGES             = $43;
  21.   MAP_PAGES                  = $44;
  22.   DEALLOCATE_PAGES           = $45;
  23.   GET_VERSION                = $46;
  24.   STATUS_OK                  = 0;
  25.  
  26.  
  27.   {------------------------------------------------------------}
  28.   { Assume the application needs one EMM page.                 }
  29.   {------------------------------------------------------------}
  30.   APPLICATION_PAGE_COUNT = 1;
  31.  
  32. Var
  33.   Regs: Registers;
  34.  
  35.   Emm_handle,
  36.   Page_Frame_Base_Address,
  37.   Pages_Needed,
  38.   Physical_Page,
  39.   Logical_Page,
  40.   Offset,
  41.   Error_Code,
  42.   Pages_EMM_Available,
  43.   Total_EMM_Pages,
  44.   Available_EMM_Pages: Integer;
  45.  
  46.   Version_Number,
  47.   Pages_Number_String: ST3;
  48.  
  49.   Verify: Boolean;
  50.  
  51.   {------------------------------------------------------------}
  52.   { The function Hex_String converts an integer into a four    }
  53.   { character hexadecimal number (string) with leading zeros.  }
  54.   {------------------------------------------------------------}
  55.   Function Hex_String (Number: Integer): ST5;
  56.     Function Hex_Char (Number: Integer): Char;
  57.       Begin
  58.         If Number < 10 then
  59.           Hex_Char := Char (Number + 48)
  60.         else
  61.           Hex_Char := Char (Number + 55);
  62.       end; { Function Hex_char }
  63.  
  64.   Var
  65.     S: ST5;
  66.  
  67.   Begin
  68.     S := '';
  69.     S := Hex_Char ((Number shr 1) div 2048);
  70.     Number := (((Number shr 1) mod 2048) shl 1) + (Number and 1);
  71.     S := S + Hex_Char (Number div 256);
  72.     Number := Number mod 256;
  73.     S := S + Hex_Char (Number div 16);
  74.     Number := Number mod 16;
  75.     S := S + Hex_Char (Number);
  76.     Hex_String := S + 'h';
  77.   end; { Function Hex_String }
  78.  
  79.  
  80.   {------------------------------------------------------------}
  81.   { The function Emm_Installed checks to see if the            }
  82.   { EMM is loaded in memory.  It does this by looking          }
  83.   { for the string 'EMMXXXX0', which should be located         }
  84.   { at 10 bytes from the beginning of the code segment the     }
  85.   { EMM interrupt, 67h, points to.                             }
  86.   {------------------------------------------------------------}
  87.   Function Emm_Installed: Boolean;
  88.     Var
  89.       Emm_Device_Name   : string[8];
  90.       Int_67_Device_Name: string[8];
  91.       Position          : integer;
  92.       Regs              : registers;
  93.  
  94.     Begin
  95.       Int_67_Device_Name := '';
  96.       Emm_Device_Name    := 'EMMXXXX0';
  97.       with Regs do
  98.         Begin
  99.           {----------------------------------------------------}
  100.           { Get the code segment interrupt 67h points to       }
  101.           { the EMM interrupt by using DOS function 35h.       }
  102.           { (get interrupt vector)                             }
  103.           {----------------------------------------------------}
  104.           AH := $35;
  105.           AL := EMM_INT;
  106.           Intr (DOS_Int, Regs);
  107.           {----------------------------------------------------}
  108.           { The ES pseudo-register contains the segment        }
  109.           { address pointed to by interrupt 67h.  Create an    }
  110.           { eight character string from the eight successive   }
  111.           { bytes at address ES:$000A (10 bytes from ES)       }
  112.           {----------------------------------------------------}
  113.           For Position := 0 to 7 do
  114.             Int_67_Device_Name :=
  115.               Int_67_Device_Name + Chr (mem[ES:Position + $0A]);
  116.           Emm_Installed := True;
  117.           {----------------------------------------------------}
  118.           { If the string is the EMM manager signature,        }
  119.           { 'EMMXXXX0', then EMM is installed and ready for    }
  120.           { use.  If not, then EMM is not present.             }
  121.           {----------------------------------------------------}
  122.           If Int_67_Device_Name <> Emm_Device_Name
  123.             then Emm_Installed := False;
  124.         end; { with Regs do }
  125.     end; { Function Emm_Installed }
  126.  
  127. End.
  128.  
  129.